package logic

import (
	"context"
	"user666/model/mysql"

	"user666/userrpc/internal/svc"
	"user666/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddLogic) Add(in *userrpc.AddRequest) (*userrpc.AddResponse, error) {
	// todo: add your logic here and delete this line
	var pro = mysql.Product{
		Name:   in.Name,
		Price:  float64(in.Price),
		Number: int(in.Number),
		UserId: int(in.UserId),
		Title:  in.Title,
	}
	mysql.DB.Create(&pro)
	return &userrpc.AddResponse{Id: int64(pro.ID)}, nil
}
